<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>写芯片</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../js/layui/css/layui.css" media="all">
</head>
<body>
<div style="width:80%;height:765px;margin:15px auto;overflow:auto;" id="aaa">
    <form class="layui-form" action="" id="update_staff">
        <input type="hidden" class="input-text" id="id" name="id">
        <input type="hidden" class="input-text" id="kk" name="kk">
        <div class="layui-form-item">
            <label class="layui-form-label">卡号</label>
            <div class="layui-input-inline" >
                <input type="text" id="cardNo" name="cardNo" readonly autocomplete="off" class="layui-input" />
            </div>
            <div class="layui-input-inline" style="width: 300px;line-height: 38px;">
                <span style="color: red;">请将工卡放入卡座，如未识别工卡，请重新放入</span>
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员编号</label>
            <div class="layui-input-block">
                <input type="text" name="bh" required lay-verify="required" autocomplete="off" readonly class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">会员姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" autocomplete="off" readonly class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block" id="xinbie">
                <input type="radio" disabled name="sex" value="1" id="nan" title="男" checked=""><div id="y" class="layui-unselect layui-form-radio layui-form-radioed" disabled><i class="layui-anim layui-icon"></i>男</div>
                <input type="radio" disabled name="sex" value="0" id="nv" title="女"><div id="x" class="layui-unselect layui-form-radio" disabled><i class="layui-anim layui-icon"></i>女</div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-block">
                <input type="text" name="phone" autocomplete="off" readonly class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>

        <!--<div class="layui-form-item">
            <label class="layui-form-label">证件号码</label>
            <div class="layui-input-block">
                <input type="text" name="sfz" autocomplete="off" readonly class="layui-input">
            </div>
            &lt;!&ndash;<div class="layui-form-mid layui-word-aux">辅助文字</div>&ndash;&gt;
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">会员头像</label>
            <div class="layui-input-block">
                <img class="layui-upload-img" name="picture" id="picture" style="width: 200px;height: 150px">
                <p id="demoText"></p>
            </div>
            <input type="hidden" class="input-text" id="logo" name="logo">
        </div>

        <div class="layui-form-item" style="margin-top: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" id="sfaffKk" lay-submit lay-filter="sfaffKk">重新开卡</button>
            </div>
        </div>
    </form>
</div>
<script src="../../js/layui/layui.all.js"></script>
<script src="../../js/config.js"></script>
<script src="../../js/token.js"></script>
<script src="./js/smartReader.js"></script>
<script src="./js/lock.js"></script>
<script src="./js/jquery.min.js"></script>
<script src="./js/card_baika.js"></script>

<script>
    function getQueryVariable(variable)
    {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }
    var can_write = false
    var staff = undefined
    window.onload = function(){
        var form = layui.form;
        $.ajax({
            url:HOST+"userInfo/getUUid",
            success:function(res) {
                $("#kk").val(res.data.kk);
            }
        });
        $.ajax({
            url:HOST+"userInfo/userInfoList?name="+getQueryVariable("name")+"&page=1&limit=10" ,
            success:function(res){
                if(res.count != 1) {
                    layer.msg("编号不正确")
                    return
                }else{
                    can_write = true
                }
                staff = res.data[0]
                $("input[name='id']").val(staff.id);
                $("input[name='name']").val(staff.name);
                $("input[name='bh']").val(staff.bh);
                var phone = staff.phone ;
                if (phone=="null" || phone==null || phone=="undefined" || phone == "") {
                    $("input[name='phone']").val("");
                }else {
                    $("input[name='phone']").val(GetQueryString("phone"));
                }
                var address = staff.address;
                if (address=="null" || address==null || address=="undefined" || address == "") {
                    $("input[name='address']").val("");
                }else {
                    $("input[name='address']").val(address);
                }
                $("input[name='logo']").val(staff.picture);
                var sfz = staff.sfz ;
                if (sfz=="null" || sfz==null || sfz=="undefined" || sfz == "") {
                    $("input[name='sfz']").val("");
                }else {
                    $("input[name='sfz']").val(sfz);
                }
                $("input[name='dqtime']").val(staff.dqtime);
                $("#message").val(staff.message);
                $('#picture').attr('src', HOST+"upload/"+staff.picture);

                var x = staff.sex;
                if(x==1){
                    $("#nan").prop("checked",true);
                    form.render()
                }else{
                    $("#nv").prop("checked",true);
                    form.render()
                }
            }
        })
    }

    layui.use(['form' , 'jquery' , 'upload'], function(){
        var form = layui.form;
        var $ = layui.jquery;
        var upload = layui.upload;

        form.on('submit(sfaffKk)',function(data){
            var cardNo = $("input[name='cardNo']").val();
            data.field.cardNo=cardNo;
            data.field.id = $("#id").val();
            var picture = $("input[name='logo']").val();
            if(cardNo==null || cardNo==""){
                layer.msg('请读取芯片');
            }else if (picture == null || picture == "") {
                layer.msg('会员头像为空不能开卡');
            }else{
                if(can_write) {
                    if(staff.cardNo != undefined && staff.cardNo != "") {
                        $.ajax({
                            url: HOST+"userInfo/reset_card?id=" + staff.id
                            , type: "GET"
                            , success: function (data) {
                                if (data.code == 200) {
                                    layer.msg("解除卡与用户绑定关系");
                                    write()
                                } else if (data.code == 500) {
                                    layer.msg(data.msg);
                                }else {
                                    layer.msg("拒绝访问");
                                }
                            }
                            , error: function () {
                                console.log("ajax error");
                            }
                        });
                    }else{
                        write()
                    }
                }
            }
            return false;
        });

        //logo上传
        var uploadInst = upload.render({
            elem: '#test'
            , url: HOST+'upload' //改成您自己的上传接口
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#picture').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //判断上传是否成功
                if (res.code == 0) {
                    $("#logo").val(res.data);
                    return layer.msg('上传成功！');
                }else{
                    return layer.msg('上传失败！');
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });

    function bhgfk() {
        var ids = $("#id").val();
        layer.prompt({
            value: '',
            title: '请输入审核不通过原因',
            btn: ['确定','取消'], //按钮，
            btnAlign: 'c',
            yes: function (index,layero) {
                var content = layero.find(".layui-layer-input").val();
                $.ajax({
                    url: HOST+"mobanZm/submitFk?uid=" + ids + "&content=" + content
                    ,type:"get"
                    , success: function (data) {
                        if(data.code==500) {
                            layer.msg('提交失败！');
                        }else if(data.code==200){
                            layer.close(layer.index);
                            layer.msg('提交成功');
                        }
                    }
                    , error: function () {
                        console.log("ajax error");
                    }
                });
            }
        }, function(value,index){
            layer.close(index);
            //执行审批不通过的内容 此时获取到的数据为value
        });
    }
</script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        var endDate= laydate.render({
            elem: '#end_time',//选择器结束时间
            type: 'datetime',
            min:"1970-1-1",//设置min默认最小值
            done: function(value,date){
                startDate.config.max={
                    year:date.year,
                    month:date.month-1,//关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                }
            }
        });

        //日期范围
        var startDate=laydate.render({
            elem: '#start_time',
            type: 'datetime',
            max:"2099-12-31",//设置一个默认最大值
            done: function(value, date){
                endDate.config.min ={
                    year:date.year,
                    month:date.month-1, //关键
                    date: date.date,
                    hours: 0,
                    minutes: 0,
                    seconds : 0
                };
            }
        });
    });
</script>
</body>
</html>